import request from '@/utils/request'

// 日志相关接口
export const log = {
  // 获取日志列表
  getLogList: (params?: any) => {
    return request({
      url: '/api/home/log/list',
      method: 'get',
      params,
    })
  },

  // 查看日志详情
  getLogDetail: (id: number) => {
    return request({
      url: '/api/home/log/view',
      method: 'get',
      params: { id },
    })
  },

  // 删除日志
  deleteLog: (id: number) => {
    return request({
      url: '/api/home/log/delete',
      method: 'delete',
      data: { id },
    })
  },

  // 获取操作类型列表
  getActionTypes: () => {
    // 由于后端没有提供专门的操作类型列表接口，我们使用静态数据
    return Promise.resolve({
      code: 0,
      msg: '获取操作类型列表成功',
      data: {
        type_actions: {
          增加: '增加',
          编辑: '编辑',
          删除: '删除',
          查看: '查看',
          登录: '登录',
          退出: '退出',
          审批: '审批',
          导出: '导出',
          导入: '导入',
          上传: '上传',
          下载: '下载',
        },
      },
    })
  },

  // 导出日志
  exportLog: (params?: any) => {
    return request({
      url: '/api/home/log/export',
      method: 'post',
      data: params,
    })
  },

  // 批量删除日志
  batchDeleteLog: (ids: number[]) => {
    return request({
      url: '/api/home/log/batch-delete',
      method: 'post',
      data: { ids },
    })
  },

  // 清空日志
  clearLog: (keep_days: number = 30) => {
    return request({
      url: '/api/home/log/clear',
      method: 'post',
      data: { keep_days },
    })
  },

  // 获取日志统计信息
  getLogStatistics: (days: number = 30) => {
    return request({
      url: '/api/home/log/statistics',
      method: 'get',
      params: { days },
    })
  },
}

// 向后兼容方法
export const getLogList = log.getLogList
export const getLogDetail = log.getLogDetail
export const deleteLog = log.deleteLog
export const getActionTypes = log.getActionTypes
export const exportLog = log.exportLog
export const batchDeleteLog = log.batchDeleteLog
export const clearLog = log.clearLog
export const getLogStatistics = log.getLogStatistics
